package com.southwind.configuration;

import com.alibaba.excel.context.AnalysisContext;

import com.alibaba.excel.event.AnalysisEventListener;
import com.southwind.entity.AdEffect;
import com.southwind.mapper.AdEffectMapper;
import org.springframework.beans.BeanUtils;

import java.util.Map;

public class BTrainPlanExcelListener extends AnalysisEventListener<AdEffect> {
    private AdEffectMapper adEffectMapper;
    public BTrainPlanExcelListener(AdEffectMapper productMapper) {
        this.adEffectMapper =productMapper;
    }

    //一行一行读取excel中内容，每读取一行调用invoke方法
    @Override
    public void invoke(AdEffect adEffect, AnalysisContext analysisContext) {
        System.out.println(adEffect);
        AdEffect product=new AdEffect();
        BeanUtils.copyProperties(adEffect, product);
        product.setId(null);
        adEffectMapper.insert(adEffect);
    }

    //读取表头的数据
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        super.invokeHeadMap(headMap, context);
        System.out.println("表头数据： " + headMap);
    }



    //所有数据读取完了之后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("ExcelListener.doAfterAllAnalysed");
    }
}